package com.pie4cloud.pie.job.executor.job;

import com.alibaba.fastjson.JSON;
import com.pie4cloud.pie.common.core.util.R;
import com.pie4cloud.pie.job.api.consumer.IHanlderConsumer;
import com.pie4cloud.pie.job.api.consumer.annotation.Hanlder;
import com.pie4cloud.pie.job.api.dto.CallBackDto;
import com.pie4cloud.pie.job.api.entity.DispenseCongfigEntity;

import com.pie4cloud.pie.job.api.entity.JobInfoEntity;
import com.pie4cloud.pie.job.api.vo.TimeLevelVo;
import com.pie4cloud.pie.job.executor.service.DispenseToolService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

@Slf4j
@Service
@RequiredArgsConstructor
@Hanlder(handler = "dispenseHistoryHandler")
public class DispenseHistoryHandlerService implements IHanlderConsumer {
	@Autowired
    private DispenseToolService dispenseToolService;

	@Override
	public R execute(String jobInfoEntity, CallBackDto callBackDto) throws Exception {
		R<String> result= new R<>();
		JobInfoEntity jobInfo=JSON.parseObject(jobInfoEntity,JobInfoEntity.class);
		DispenseCongfigEntity dispenseCongfigEntity=JSON.parseObject(jobInfo.getExecutorParam(),DispenseCongfigEntity.class);
		List<TimeLevelVo> timeLevelVos=new ArrayList<>();
		dispenseToolService.computingTime(dispenseCongfigEntity,timeLevelVos,result);
		for(TimeLevelVo timeLevelVo:timeLevelVos){
			dispenseToolService.scanPreFolder(dispenseCongfigEntity,timeLevelVo,result);
		}
		return result;
	}


}
